import { defineStore } from "pinia";

export const useUserInfoStore = defineStore({
  id: "userInfo",
  // 修改默认值之后，需清除 localStorage 数据
  state: () => ({
    nickName: "",
    avatarUrl: "",
    id: null,
    // 微信唯一标识
    openId: ""
  }),
  actions: {
    setGlobalState(...args) {
      this.$patch({ [args[0]]: args[1] });
    },
    setLoginInfo(openId, id) {
      this.openId = openId;
      this.id = id;
    },
    setUserInfo(nickName, avatarUrl) {
      this.nickName = nickName;
      this.avatarUrl = avatarUrl;
    }
  }
});
